#include <reg51.h>
#include "ds18b20.h"
#include "uart.h"
#include <stdio.h> // 添加标准输入输出头文件
#include <intrins.h>

void Delayms(unsigned int ms)
{
    unsigned int i, j;
    for (i = ms; i > 0; i--)
        for (j = 110; j > 0; j--)
            ;
}

void main()
{
    float temp;
    char buffer[16];

    UART_Init(); // 初始化串口

    UART_SendString("Hello, World!\r\n");

    // 测试能否正常初始化
    if (!DS18B20_Reset())
    {
        UART_SendString("Sensor found!\r\n");
        UART_SendString("Everything ready!\r\n");
    }
    else
    {
        UART_SendString("Sensor not found!\r\n");
    }
    Delayms(1000); // 1秒间隔

    while (1)
    {
        // temp = DS18B20_GetTemp();

        ds18b20_ConvertT();
        temp = DS18B20_GetTemp();

        sprintf(buffer, "%.3f\r\n", temp);
        UART_SendString("Temperature: ");
        UART_SendString(buffer);
        UART_SendString(" C\r\n");

        Delayms(1000); // 1秒间隔
    }
}